home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu / asembler.arc / DO1.C < prev    next >
Text File  |  1987-12-09  |  3KB  |  157 lines

  1. /*
  2.  *      MC6801 specific processing
  3.  */
  4.  
  5. /* addressing modes */
  6. #define IMMED   0       /* immediate */
  7. #define IND     1       /* indexed */
  8. #define OTHER   2       /* NOTA */
  9.  
  10. /*
  11.  *      localinit --- machine specific initialization
  12.  */
  13. localinit()
  14. {
  15. }
  16.  
  17. /*
  18.  *      do_op --- process mnemonic
  19.  *
  20.  *    Called with the base opcode and it's class. Optr points to
  21.  *    the beginning of the operand field.
  22.  */
  23. do_op(opcode,class)
  24. int opcode;    /* base opcode */
  25. int class;    /* mnemonic class */
  26. {
  27.     int     dist;   /* relative branch distance */
  28.     int     amode;  /* indicated addressing mode */
  29.     char    *peek;
  30.  
  31.     /* guess at addressing mode */
  32.     peek = Optr;
  33.     amode = OTHER;
  34.     while( !delim(*peek) && *peek != EOS)  /* check for comma in operand field */
  35.         if( *peek++ == ',' ){
  36.             amode = IND;
  37.             break;
  38.             }
  39.     if( *Optr == '#' ) amode = IMMED;
  40.  
  41.     switch(class){
  42.         case INH:                       /* inherent addressing */
  43.             emit(opcode);
  44.             return;
  45.         case GEN:                       /* general addressing */
  46.             do_gen(opcode,amode);
  47.             return;
  48.         case REL:                       /* relative branches */
  49.             eval();
  50.             dist = Result - (Pc+2);
  51.             emit(opcode);
  52.             if( (dist >127 || dist <-128) && Pass==2){
  53.                 error("Branch out of Range");
  54.                 emit(lobyte(-2));
  55.                 return;
  56.                 }
  57.             emit(lobyte(dist));
  58.             return;
  59.         case NOIMM:
  60.             if( amode == IMMED){
  61.                 error("Immediate Addressing Illegal");
  62.                 return;
  63.                 }
  64.             do_gen(opcode,amode);
  65.             return;
  66.         case LONGIMM:
  67.             if( amode == IMMED ){
  68.                 emit(opcode);
  69.                 Optr++;
  70.                 eval();
  71.                 eword(Result);
  72.                 return;
  73.                 }
  74.             do_gen(opcode,amode);
  75.             return;
  76.         case GRP2:
  77.             if( amode == IND ){
  78.                 do_indexed(opcode);
  79.                 return;
  80.                 }
  81.             /* extended addressing */
  82.             eval();
  83.             emit(opcode+0x10);
  84.             eword(Result);
  85.             return;
  86.         default:
  87.             fatal("Error in Mnemonic table");
  88.         }
  89. }
  90.  
  91. /*
  92.  *      do_gen --- process general addressing modes
  93.  */
  94. do_gen(op,mode)
  95. int     op;
  96. int     mode;
  97. {
  98.     if( mode == IMMED){
  99.         Optr++;
  100.         emit(op);
  101.         eval();
  102.         emit(lobyte(Result));
  103.         return;
  104.         }
  105.     else if( mode == IND ){
  106.         Cycles+=2;
  107.         do_indexed(op+0x20);
  108.         return;
  109.         }
  110.     else if( mode == OTHER){
  111.         eval();
  112.         if(Force_word){
  113.             emit(op+0x30);
  114.             eword(Result);
  115.             Cycles+=2;
  116.             return;
  117.             }
  118.         if(Force_byte){
  119.             emit(op+0x10);
  120.             emit(lobyte(Result));
  121.             Cycles++;
  122.             return;
  123.             }
  124.         if(Result>=0 && Result <=0xFF){
  125.             emit(op+0x10);
  126.             emit(lobyte(Result));
  127.             Cycles++;
  128.             return;
  129.             }
  130.         else {
  131.             emit(op+0x30);
  132.             eword(Result);
  133.             Cycles+=2;
  134.             return;
  135.             }
  136.         }
  137.     else {
  138.         error("Unknown Addressing Mode");
  139.         return;
  140.         }
  141. }
  142.  
  143. /*
  144.  *      do_indexed --- handle all wierd stuff for indexed addressing
  145.  */
  146. do_indexed(op)
  147. int op;
  148. {
  149.     emit(op);
  150.     eval();
  151.     if( mapdn(*++Optr) != 'x' )
  152.         warn("Indexed Addressing Assumed");
  153.     if( Result < 0 || Result > 255)
  154.         warn("Value Truncated");
  155.     emit(lobyte(Result));
  156. }
  157.